#include "vtkTexureMappingByOrientation.h"
#include "vtkCellData.h"
#include "vtkDataSet.h"
#include "vtkFloatArray.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkLine.h"
#include "vtkMath.h"
#include "vtkOBBTree.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkPoints.h"
#include "vtkTextureMapToSphere.h"
#include "vtkTextureMapToPlane.h"
#include "vtkTextureMapToCylinder.h"

vtkCxxRevisionMacro(vtkTexureMappingByOrientation, "$Revision: 1.00 $");
vtkStandardNewMacro(vtkTexureMappingByOrientation);

vtkTexureMappingByOrientation::vtkTexureMappingByOrientation(void)
{
}

vtkTexureMappingByOrientation::~vtkTexureMappingByOrientation(void)
{
}

int vtkTexureMappingByOrientation::RequestData( vtkInformation * request,
											   vtkInformationVector **inputVector,
											   vtkInformationVector *outputVector)
 {

	 // get the info objects
	 vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
	 vtkInformation *outInfo = outputVector->GetInformationObject(0);

	 // get the input and ouptut
	 vtkDataSet *input = vtkDataSet::SafeDownCast(
		 inInfo->Get(vtkDataObject::DATA_OBJECT()));
	 vtkDataSet *output = vtkDataSet::SafeDownCast(
		 outInfo->Get(vtkDataObject::DATA_OBJECT()));


	 vtkTextureMapToPlane * textureMap = vtkTextureMapToPlane::New();
	 textureMap->SetInput(input);
	 textureMap->Update();
	 output->ShallowCopy(textureMap->GetOutput());
	 textureMap->Delete();

	// vtkFloatArray *newTCoords;
	// vtkIdType numPts=input->GetNumberOfPoints();
	// vtkIdType ptId;
	// int i;
	// double x[3], tc[2], thetaX, thetaY, closest[3], v[3];
	// double axis[3], vP[3], vec[3];

	// vtkDebugMacro(<<"Generating Cylindrical Texture Coordinates");

	// // First, copy the input to the output as a starting point
	// output->CopyStructure( input );

	// if ( numPts < 1 )
	// {
	//	 vtkErrorMacro(<<"Can't generate texture coordinates without points");
	//	 return 1;
	// }


	//
	// newTCoords = vtkFloatArray::New();
	// newTCoords->SetName("Texture Coordinates");
	// newTCoords->SetNumberOfComponents(2);
	// newTCoords->Allocate(2*numPts);


	// tc[0] = 0;
	// tc[1] = 0;
	//newTCoords->InsertTuple(0,tc);

	//tc[0] = 1;
	//tc[1] = 0;
	//newTCoords->InsertTuple(1,tc);

	//tc[0] = 1;
	//tc[1] = 1;
	//newTCoords->InsertTuple(2,tc);

	//tc[0] = 0;
	//tc[1] = 1;
	//newTCoords->InsertTuple(3,tc);


	// output->GetPointData()->CopyTCoordsOff();
	// output->GetPointData()->PassData(input->GetPointData());
	// output->GetCellData()->PassData(input->GetCellData());

	// output->GetPointData()->SetTCoords(newTCoords);
	// newTCoords->Delete();


	 return 1;

 }
